<% provide(:page_title, titleize(t(:books_index))) %>
<div class="page-header">
    <h1><%= titleize(t(:books_index))%></h1>
</div>
<div class="well">
<table id="books" class="table table-striped table-bordered table-hover">
  <thead>
    <tr>
      <th><%= titleize(t(:title))%></th>
      <th><%= titleize(t(:author))%></th>
      <th><%= titleize(t(:photo))%></th>
      <th><%= titleize(t(:quantity))%></th>
      <th><%= titleize(t(:language))%></th>
      <th><%= titleize(t(:place))%></th>
      <th></th>
      <% if signed_in? && current_user.admin? %>
          <th></th>
          <th></th>
      <% end %>
    </tr>
  </thead>

  <tbody>
    <% @books.each do |book| %>
      <tr>
        <td><%= book.title %></td>
        <td><%= book.author.name_and_surname if book.author %></td>
        <td>
          <% if book.photo.blank? %>
             <img src="/assets/default_pic.jpg" height='100px' width='100px' alt='' title="<%= titleize(t(:photo)) %>" />  
          <% else %>
             <%= image_tag book.photo,  size: '100x100', alt: '', title: titleize(t(:photo)) %>   
          <% end %>
        </td>
        
        <td><%= book.quantity %></td>
        <td><%= book.language %></td>
        <td><%= book.place %></td>
        <td><%= link_to titleize(t(:show)), book %></td>
        <% if signed_in? && current_user.admin? %>
            <td><%= link_to titleize(t(:edit)), edit_book_path(book) %></td>
            <td><%= link_to titleize(t(:destroy)), book, method: :delete, data: { confirm: titleize(t(:are_you_sure)) } %></td>
        <% end %>
      </tr>
    <% end %>
  </tbody>
</table>
</div>
<br>

<% if signed_in? && current_user.admin? %>
    <%= link_to titleize(t(:add_book)), new_book_path %>
<% end %>
